﻿Imports PadovadoAPI
Imports System.Data
Imports PadovadoAPI.Utente

Partial Class Admin
    Inherits System.Web.UI.Page

    'Protected Sub Login1_Authenticate(sender As Object, e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
    '    Dim sql As String = "SELECT PK_Utente FROM Utente WHERE Username = '" & Login1.UserName & "' AND Password = '" & Utente.md5(Login1.Password) & "'"
    '    ' Throw New Exception(sql)
    '    Dim Usr As Utente
    '    Dim dbo As New DBObject
    '    Dim pk_utente As Integer = dbo.ExecuteScalar(sql, Nothing, CommandType.Text)
    '    Usr = Utente.LoadFromPk(pk_utente)
    '    If Usr.intRuolo = Ruolo.Admin Then
    '        Response.Redirect("AdminMenu.aspx")
    '    End If
    'End Sub

    Protected Sub Login1_Authenticate(sender As Object, e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
        Dim sql As String = "SELECT PK_Utente, intRuolo FROM Utente WHERE Username = '" & Login1.UserName & "' AND Password = '" & Utente.md5(Login1.Password) & "'"
        'Throw New Exception(sql)
        '  Dim Usr As Utente
        Dim dbo As New DBObject
        Dim ds As New DataSet
        ds = dbo.FillDS(sql, Nothing, CommandType.Text)
        If Not IsNothing(ds) AndAlso Not IsNothing(ds.Tables) AndAlso ds.Tables.Count > 0 AndAlso ds.Tables(0).Rows.Count > 0 Then
            'Usr.PK_User = objpk
            If ds.Tables(0).Rows(0).Item("intRuolo").ToString = Ruolo.Admin Then
                e.Authenticated = True
                Session("UserInSession") = Login1.UserName
                Response.Redirect("AdminMenu.aspx")
            End If
        End If
        e.Authenticated = False
    End Sub

End Class